Repository navigation
add tag-based indexing with allow and deny lists - #277
MichelleAntunes wants to merge 1 commit into
Conversation
|
Hello there, We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process. Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6 Thank you for contributing to Nextcloud and we hope to hear from you soon! (If you believe you should not receive this message, you can add yourself to the blocklist.) |
| $lastFileIdSeen = $fileId; | ||
| $mountFilesCount++; | ||
|
|
||
| $node = $this->rootFolder->getFirstNodeById($fileId); |
There was a problem hiding this comment.
This is sadly immensely inefficient.
|
thank you for your effort in crafting this PR. |
Hi @kyteinsky, thank you for the detailed direction, and sorry for the late reply. I'm happy to rework the PR. My understanding of the plan:
I’d like to do all of these now. One question on point 2: a tags option in the server’s getByAncestorInStorage would be the cleanest way, but as far as I understand it would only be available from Nextcloud 35 on. Until then, would you accept a DB-side query inside the app (joining the tag mappings with the file cache), or would you prefer that I wait for the server API option? If the server gets the option later, I’m happy to switch to it. Since the PR is already large, I can also split it into smaller ones. Let me know what you prefer. |
Admins can limit what Context Chat indexes with system tags. The index mode is either "all" (the default, unchanged) or "tag_only". In tag mode the admin picks an allow list and a deny list of tags: - allow list only: index what has an allow tag - deny list only: index everything except what has a deny tag - both: index what has an allow tag and no deny tag A tag on a folder covers everything inside it, and the same tag cannot be in both lists. - TagEligibilityService decides whether a file may be indexed. The queue checks it again when an item is processed, so a stale item is dropped. - Tag and file events keep the index in line: a file that is no longer eligible is removed, one that became eligible is queued. - Switching the mode schedules a full cleanup (to tag mode) or a full indexing run (back to all). When only the lists change, one small job per added or removed tag looks at the files that carry that tag, instead of reading every file again. - occ context_chat:cleanup-untagged runs the cleanup by hand. - IndexCompletionService holds the "initial indexing completed" check, moved out of QueueController so the cleanup can use it too. It keeps the checks of the controller and also waits for cleanup crawl jobs and pending actions. - The admin settings get the mode switch and the two tag selectors. Changes are saved at once and the server explains why it refuses one. - Users get a notification, created by a background job, when the admin switches to tag mode. It goes away when the admin switches back. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AL889gRk3a2UdQAufak8m9 Signed-off-by: MichelleAntunes <miichelleantunes@outlook.com>
cd1bd6a to
8c0c4c1
Compare
|
I reworked the PR and rebased it on current Done, from the plan above:
Not done yet:
The PR description is updated. |
|
thank you very much!
we can add this soon in the server repo and keep going that route when it's available or fallback to this method when it's not
that's fine. |
Fixes #278.
Why this matters
Context Chat currently indexes every document matching its mimetype whitelist, with no way to exclude anything. For organizations handling sensitive or confidential material — legal, healthcare, HR, compliance-regulated industries — there's currently no way to control which content gets sent to an LLM for embedding. Everything eligible is indexed by default, which is the wrong default for these environments: it means adopting Context Chat requires either accepting that every eligible document becomes part of the AI's knowledge base, or not adopting it at all.
This PR adds an opt-in mode in which admins decide with regular Nextcloud system tags what is indexed. The default is unchanged: existing instances keep indexing everything, and nothing changes for anyone unless an admin deliberately switches the mode.
How it works
On the Context Chat admin settings page the admin chooses the indexing mode:
In tag mode the admin picks two lists of system tags, Allow tags and Deny tags:
Keeping the index in line with the rules
occ context_chat:cleanup-untaggedruns the cleanup by hand.Design decisions worth calling out
TagEligibilityServiceanswers "may this file be indexed?". The file and tag listeners, the queue and the jobs all ask it, so the rules exist once.QueueControllertoIndexCompletionServiceso the tag cleanup can use it as well. It keeps the logic of the recent rewrite inQueueController(seedinglast_enqueued_db_id, empty-queue fallback) and also waits for cleanup crawl jobs and pending queue actions.Testing
Tested manually on a Nextcloud 35.0.2 instance (Assistant 4.1.0, Context Chat backend 5.5.0) with several users, after rebasing on current
main(including #298): switching between the modes in both directions, the three allow/deny combinations, folder inheritance, changing the lists in tag mode, the user notification appearing and going away, the admin screen (including the refusal messages), the app upgrade, and a Context Chat query returning only sources that match the rules after a reindex.🤖 AI (if applicable)